package com.vpclub.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Locale;

/**
 * @author : leimingchao
 * @date Date : 2021年07月31日 22:02
 */
@Controller
public class I18TestController {

    @Autowired
    private MessageSource messageSource;

    @RequestMapping(value = "/toLoginPage")
    public String toLoginPage(@RequestParam(value = "locale",required = false,defaultValue = "zh_CH") String localeStr, Locale locale, Model model, HttpSession httpSession) {
        System.out.println(locale);
        System.out.println(messageSource.getClass());
        String welcomeInfo = messageSource.getMessage("welcomeInfo", null, locale);
        System.out.println(welcomeInfo);
        // Locale l = null;
        // model.addAttribute("msg",welcomeInfo);
        // //如果带了locale参数，就用参数指定的区域信息，如果没带就用请求头的
        // if (!StringUtils.isEmpty(localeStr)) {
        //     String[] split = localeStr.split("_");
        //     l = new Locale(split[0],split[1]);
        // } else {
        //     l = locale;
        // }
        // httpSession.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,l);
        return "login";
    }
}
